home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / ADA / GNAT / !gcc / adainc / 2 / adb / a-wtdeio < prev    next >
Text File  |  1996-02-12  |  7KB  |  181 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT RUNTIME COMPONENTS                          --
  4. --                                                                          --
  5. --   A D A . T E X T _ I O . W I D E _ T E X T _ I O . D E C I M A L _ I O  --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.3 $                              --
  10. --                                                                          --
  11. --     Copyright (C) 1992,1993,1994,1995 Free Software Foundation, Inc.     --
  12. --                                                                          --
  13. -- GNAT is free software;  you can  redistribute it  and/or modify it under --
  14. -- terms of the  GNU General Public License as published  by the Free Soft- --
  15. -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
  16. -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
  17. -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  18. -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
  19. -- for  more details.  You should have  received  a copy of the GNU General --
  20. -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
  21. -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
  22. -- MA 02111-1307, USA.                                                      --
  23. --                                                                          --
  24. -- As a special exception,  if other files  instantiate  generics from this --
  25. -- unit, or you link  this unit with other files  to produce an executable, --
  26. -- this  unit  does not  by itself cause  the resulting  executable  to  be --
  27. -- covered  by the  GNU  General  Public  License.  This exception does not --
  28. -- however invalidate  any other reasons why  the executable file  might be --
  29. -- covered by the  GNU Public License.                                      --
  30. --                                                                          --
  31. -- GNAT was originally developed  by the GNAT team at  New York University. --
  32. -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
  33. --                                                                          --
  34. ------------------------------------------------------------------------------
  35.  
  36. with Ada.Text_IO.Decimal_Aux;
  37. with System.WCh_Con; use System.WCh_Con;
  38. with System.WCh_WtS; use System.WCh_WtS;
  39.  
  40. with Ada.Unchecked_Conversion;
  41.  
  42. package body Ada.Text_IO.Wide_Text_IO.Decimal_IO is
  43.  
  44.    subtype TFT is Ada.Text_IO.File_Type;
  45.    --  File type required for calls to routines in Aux
  46.  
  47.    package Aux renames Ada.Text_IO.Decimal_Aux;
  48.    --  We can share the normal Text_IO circuits for the non-string cases
  49.    --  since numeric values involve no wide character values, and the first
  50.    --  character of a wide character value (ESC or an upper half character)
  51.    --  always looks non-numeric for the Get case). For the Wide_String cases
  52.    --  we can share the normal Text_IO circuits by converting to String.
  53.  
  54.    Scale : constant Integer := Num'Scale;
  55.  
  56.    ---------
  57.    -- Get --
  58.    ---------
  59.  
  60.    procedure Get
  61.      (File  : in File_Type;
  62.       Item  : out Num;
  63.       Width : in Field := 0)
  64.    is
  65.    begin
  66.       if Num'Size > Integer'Size then
  67.          Item := Num (Aux.Get_LLD (TFT (File), Width, Scale));
  68.          --  Item := Num'Fixed_Value (Aux.Get_LLD (TFT (File), Width, Scale));
  69.          --  above is what we should write, but gets assert error ???
  70.  
  71.       else
  72.          Item := Num (Aux.Get_Dec (TFT (File), Width, Scale));
  73.          --  Item := Num'Fixed_Value (Aux.Get_Dec (TFT (File), Width, Scale));
  74.          --  above is what we should write, but gets assert error ???
  75.       end if;
  76.  
  77.    exception
  78.       when Constraint_Error => raise Data_Error;
  79.    end Get;
  80.  
  81.    procedure Get
  82.      (Item  : out Num;
  83.       Width : in Field := 0)
  84.    is
  85.    begin
  86.       Get (Current_Input, Item, Width);
  87.    end Get;
  88.  
  89.    procedure Get
  90.      (From : in Wide_String;
  91.       Item : out Num;
  92.       Last : out Positive)
  93.    is
  94.       S : constant String := Wide_String_To_String (From, WCEM_Upper);
  95.       --  String on which we do the actual conversion. Note that the method
  96.       --  used for wide character encoding is irrelevant, since if there is
  97.       --  a character outside the Standard.Character range then the call to
  98.       --  Aux.Gets will raise Data_Error in any case.
  99.  
  100.    begin
  101.       if Num'Size > Integer'Size then
  102.          --  Item := Num'Fixed_Value
  103.          --  should write above, but gets assert error ???
  104.          Item := Num
  105.                    (Aux.Gets_LLD (S, Last'Unrestricted_Access, Scale));
  106.       else
  107.          --  Item := Num'Fixed_Value
  108.          --  should write above, but gets assert error ???
  109.          Item := Num
  110.                    (Aux.Gets_Dec (S, Last'Unrestricted_Access, Scale));
  111.       end if;
  112.  
  113.    exception
  114.       when Constraint_Error => raise Data_Error;
  115.    end Get;
  116.  
  117.    ---------
  118.    -- Put --
  119.    ---------
  120.  
  121.    procedure Put
  122.      (File : in File_Type;
  123.       Item : in Num;
  124.       Fore : in Field := Default_Fore;
  125.       Aft  : in Field := Default_Aft;
  126.       Exp  : in Field := Default_Exp)
  127.    is
  128.    begin
  129.       if Num'Size > Integer'Size then
  130.          Aux.Put_LLD
  131. --           (TFT (File), Long_Long_Integer'Integer_Value (Item),
  132. --  ???
  133.            (TFT (File), Long_Long_Integer (Item),
  134.             Fore, Aft, Exp, Scale);
  135.       else
  136.          Aux.Put_Dec
  137. --           (TFT (File), Integer'Integer_Value (Item), Fore, Aft, Exp, Scale);
  138. --  ???
  139.            (TFT (File), Integer (Item), Fore, Aft, Exp, Scale);
  140.  
  141.       end if;
  142.    end Put;
  143.  
  144.    procedure Put
  145.      (Item : in Num;
  146.       Fore : in Field := Default_Fore;
  147.       Aft  : in Field := Default_Aft;
  148.       Exp  : in Field := Default_Exp)
  149.    is
  150.    begin
  151.       Put (Current_Output, Item, Aft, Exp);
  152.    end Put;
  153.  
  154.    procedure Put
  155.      (To   : out Wide_String;
  156.       Item : in Num;
  157.       Aft  : in Field := Default_Aft;
  158.       Exp  : in Field := Default_Exp)
  159.    is
  160.       S : String (To'First .. To'Last);
  161.  
  162.    begin
  163.       if Num'Size > Integer'Size then
  164. --       Aux.Puts_LLD
  165. --         (S, Long_Long_Integer'Integer_Value (Item), Aft, Exp, Scale);
  166. --  ???
  167.          Aux.Puts_LLD
  168.            (S, Long_Long_Integer (Item), Aft, Exp, Scale);
  169.       else
  170. --       Aux.Puts_Dec (S, Integer'Integer_Value (Item), Aft, Exp, Scale);
  171. --  ???
  172.          Aux.Puts_Dec (S, Integer (Item), Aft, Exp, Scale);
  173.       end if;
  174.  
  175.       for J in S'Range loop
  176.          To (J) := Wide_Character'Val (Character'Pos (S (J)));
  177.       end loop;
  178.    end Put;
  179.  
  180. end Ada.Text_IO.Wide_Text_IO.Decimal_IO;
  181.